﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BuildForm
{
    public partial class ParentForm : Form
    {
        Employees tblEmployees = null;
        Categories tblCatogories = null;
        Products tblProducts = null;
        Suppliers tblSuppliers = null;
        Customers tblCustomers = null;
        Orders tblOrders = null;
        Shippers tblShippers = null;


        public ParentForm()
        {
            InitializeComponent();
        }

        #region ShowTable
        private void cascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void verticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void horizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void tsmiEmployees_Click(object sender, EventArgs e)
        {
            try
            {
                if (tblEmployees == null)
                {
                    tblEmployees = new Employees();
                    tblEmployees.MdiParent = this;
                    tblEmployees.FormClosed += new FormClosedEventHandler(tblEmployees_FormClosed);
                }
                else
                {
                    tblEmployees.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        void tblEmployees_FormClosed(object sender, FormClosedEventArgs e)
        {
            tblEmployees = null;
        }

        private void tsmiCategories_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (tblCatogories == null)
                {
                    tblCatogories = new Categories();
                    tblCatogories.MdiParent = this;
                    tblCatogories.FormClosed += new FormClosedEventHandler(tblCatogories_FormClosed);
                    tblCatogories.Show();
                }
                else
                {
                    tblCatogories.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        void tblCatogories_FormClosed(object sender, FormClosedEventArgs e)
        {
            tblCatogories = null;
        }

        private void tsmiProducts_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (tblProducts == null)
                {
                    tblProducts = new Products();
                    tblProducts.MdiParent = this;
                    tblProducts.FormClosed += new FormClosedEventHandler(tblProducts_FormClosed);
                    tblProducts.Show();
                }
                else
                {
                    tblProducts.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        void tblProducts_FormClosed(object sender, FormClosedEventArgs e)
        {
            tblProducts = null;
        }

        private void tsmiSuppliers_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (tblSuppliers == null)
                {
                    tblSuppliers = new Suppliers();
                    tblSuppliers.MdiParent = this;
                    tblSuppliers.FormClosed += new FormClosedEventHandler(tblSuppliers_FormClosed);
                    tblSuppliers.Show();
                }
                else
                {
                    tblSuppliers.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        void tblSuppliers_FormClosed(object sender, FormClosedEventArgs e)
        {
            tblSuppliers = null;
        }

        private void tsmiCustomers_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (tblCustomers ==null)
                {
                    tblCustomers = new Customers();
                    tblCustomers.MdiParent = this;
                    tblCustomers.FormClosed += new FormClosedEventHandler(tblCustomers_FormClosed);
                    tblCustomers.Show();
                }
                else
                {
                    tblCustomers.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        void tblCustomers_FormClosed(object sender, FormClosedEventArgs e)
        {
            tblCustomers = null;
        }


        private void tsmiOrders_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (tblOrders == null)
                {
                    tblOrders = new Orders();
                    tblOrders.MdiParent = this;
                    tblOrders.FormClosed += new FormClosedEventHandler(tblOrders_FormClosed);
                    tblOrders.Show();
                }
                else
                {
                    tblOrders.Activate();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        void tblOrders_FormClosed(object sender, FormClosedEventArgs e)
        {
            tblOrders = null;
        }

        private void tsmiShippers_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (tblShippers == null)
                {
                    tblShippers = new Shippers();
                    tblShippers.MdiParent = this;
                    tblShippers.FormClosed += new FormClosedEventHandler(tblShippers_FormClosed);
                    tblShippers.Show();
                }
                else
                {
                    tblShippers.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        void tblShippers_FormClosed(object sender, FormClosedEventArgs e)
        {
            tblShippers = null;
        }

        #endregion

        private void tsbtEmployees_Click(object sender, EventArgs e)
        {
            try
            {
                if (tblEmployees == null)
                {
                    tblEmployees = new Employees();
                    tblEmployees.MdiParent = this;
                    tblEmployees.FormClosed +=new FormClosedEventHandler(tblEmployees_FormClosed);
                    tblEmployees.Show();
                }
                else
                {
                    tblEmployees.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void tsbtCategories_Click(object sender, EventArgs e)
        {
            try
            {
                if (tblCatogories == null)
                {
                    tblCatogories = new Categories();
                    tblCatogories.MdiParent = this;
                    tblCatogories.FormClosed +=new FormClosedEventHandler(tblCatogories_FormClosed);
                    tblCatogories.Show();
                }
                else
                {
                    tblCatogories.Activate();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void tsbtProducts_Click(object sender, EventArgs e)
        {
            try
            {
                if (tblProducts == null)
                {
                    tblProducts = new Products();
                    tblProducts.MdiParent = this;
                    tblProducts.FormClosed+=new FormClosedEventHandler(tblProducts_FormClosed);
                    tblProducts.Show();
                }
                else
                {
                    tblProducts.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void tsbtSuppliers_Click(object sender, EventArgs e)
        {
            try
            {
                if (tblSuppliers ==null)
                {
                    tblSuppliers = new Suppliers();
                    tblSuppliers.MdiParent = this;
                    tblSuppliers.FormClosed+=new FormClosedEventHandler(tblSuppliers_FormClosed);
                    tblSuppliers.Show();
                }
                else
                {
                    tblSuppliers.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void tsbtCustomers_Click(object sender, EventArgs e)
        {
            try
            {
                if (tblCustomers == null)
                {
                    tblCustomers = new Customers();
                    tblCustomers.MdiParent = this;
                    tblCustomers.FormClosed +=new FormClosedEventHandler(tblCustomers_FormClosed);
                    tblCustomers.Show();
                }
                else
                {
                    tblCustomers.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        private void tsbtOrders_Click(object sender, EventArgs e)
        {
            try
            {
                if (tblOrders == null)
                {
                    tblOrders = new Orders();
                    tblOrders.MdiParent = this;
                    tblOrders.FormClosed+=new FormClosedEventHandler(tblOrders_FormClosed);
                    tblOrders.Show();
                }
                else
                {
                    tblOrders.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void tsbtShippers_Click(object sender, EventArgs e)
        {
            try
            {
                if (tblShippers == null)
                {
                    tblShippers = new Shippers();
                    tblShippers.MdiParent = this;
                    tblShippers.FormClosed+=new FormClosedEventHandler(tblShippers_FormClosed);
                    tblShippers.Show();
                }
                else
                {
                    tblShippers.Activate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void closeAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tblShippers != null)
            {
                tblShippers.Close(); 
            }
            if (tblSuppliers != null)
            {
                tblSuppliers.Close(); 
            }
            if (tblProducts != null)
            {
                tblProducts.Close(); 
            }
            if (tblEmployees != null)
            {
                tblEmployees.Close(); 
            }
            if (tblOrders != null)
            {
                tblOrders.Close(); 
            }
            if (tblCustomers != null)
            {
                tblCustomers.Close(); 
            }
            if (tblCatogories != null)
            {
                tblCatogories.Close(); 
            }
        }



    }
}
